package org.wxl.liangpicturebackend.common;

import org.wxl.liangpicturebackend.exception.ErrorCode;

public class ResultUtils {

    /**
     * 成功返回
     * @param data
     * @return
     * @param <T>
     */
    public static <T> BaseResponse<T> success(T data) {
        return new BaseResponse<>(0, data, "ok");
    }

    /**
     * 成功返回
     * @param data
     * @param msg
     * @return
     * @param <T>
     */
    public static <T> BaseResponse<T> success(T data, String msg) {
        return new BaseResponse<>(0, data, msg);
    }

    /**
     * 成功返回
     * @param data
     * @param code
     * @return
     * @param <T>
     */
    public static <T> BaseResponse<T> success(T data, int code) {
        return new BaseResponse<>(code, data, "ok");
    }

    /**
     * 失败返回
     * @param errorCode
     * @return
     * @param <T>
     */
    public static <T> BaseResponse<T> error(ErrorCode errorCode) {
        return new BaseResponse<>(errorCode);
    }

    /**
     * 失败返回
     * @param errorCode
     * @param msg
     * @return
     * @param <T>
     */
    public static <T> BaseResponse<T> error(ErrorCode errorCode, String msg) {
        return new BaseResponse<>(errorCode.getCode(),null, msg);
    }

    public static <T> BaseResponse<T> error(int code, String msg) {
        return new BaseResponse<>(code,null, msg);
    }
}
